package dingadmin

import (
	"github.com/gofiber/fiber/v2"
	"os"
	"strconv"
)

func (i *Engine) Start() {
	i.logger.Info("正在启动服务器在" + strconv.Itoa(i.configData.Port) + "端口...")
	err := i.server.Listen("0.0.0.0:" + strconv.Itoa(i.configData.Port))
	if err != nil {
		i.logger.Error("启动服务器失败！" + err.Error())
		os.Exit(0)
	}
}

func (i *Engine) GetServer() *fiber.App {
	return i.server
}

func (i *Engine) GetRouter() fiber.Router {
	return i.router
}

func (i *Engine) GET(path string, templateName string, getFunc func(ctx *fiber.Ctx) map[string]interface{}) {
	i.router.Get(path, func(ctx *fiber.Ctx) error {
		return ctx.Render(templateName, getFunc(ctx), "layout")
	})
}

func (i *Engine) Static(prepath string, path string) {
	i.server.Static(prepath, path)
}
